#ifndef GPUBUFFER_H
#define GPUBUFFER_H

#include "Resource.h"
#include "CommonTypes.h"

namespace Cvekas {

/// \brief Base for IndexBuffer and VertexBuffer
///
/// Abstracts common functionality between index and vertex buffers.
/// Doesn't do much now, acts mainly as helper for easy porting to D3D10, 
/// where index and vertex buffers have a lot in common.
class GpuBuffer : public Resource
{
public:
	/// Constructor
	GpuBuffer(ResourceId id, D3DDevicePtr device, const std::string& name, bool is_dynamic)
		: Resource(name, id), device(device), is_released(false), is_dynamic(is_dynamic) {};

	/// Destructor
	virtual ~GpuBuffer() {}

	/// Is this buffer dynamic?
	bool isDynamic() const { return is_dynamic; }
	
	/// Returns size of buffer in bytes
	uint getSizeInBytes() const { return size_in_bytes; }

	/// Locks vertex buffer. Throws Exception if buffer is already locked.
	/// \param read_only Pass true if no writing to locked buffer will be done, it improves performance.
	virtual LockedBuffer lock(bool read_only) = 0;
	/// Unlocks locked buffer. Throws Exception if buffer is not locked.
	virtual void unlock() = 0;
	/// Returns true if buffer is currently locked
	virtual bool isLocked() const = 0;

	virtual void onDeviceLost() = 0;
	virtual void onDeviceReset() = 0;

protected:
	D3DDevicePtr device;
	uint size_in_bytes;
	bool is_released;
	const bool is_dynamic;
};

typedef boost::shared_ptr<GpuBuffer> GpuBufferPtr;

} // namespace

#endif